<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html >
<html>
<head>
<base href="<%=basePath%>">
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>用户管理</title>
<link rel="stylesheet" href="<%=basePath%>res/wzw/layui/css/layui.css"
	media="all">
<style>
body {
	margin: 10px;
}

.demo-carousel {
	height: 300px;
	line-height: 300px;
	text-align: center;
}oi</style>
</head>
<body>
	<div class="demoTable">
		搜索用户名称：
		<div class="layui-inline">
			<input class="layui-input" name="userName" id="demoReload"
				autocomplete="off">
		</div>
		<button class="layui-btn" data-type="reload">搜索</button>
		<button class="layui-btn" id="manAdd" data-type="add">增加</button>
	</div>
	<table class="layui-hide" id="goods" lay-filter="demo"></table>

	<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit" id="imgUpdate">修改</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


	<script src="<%=basePath%>res/wzw/layui/layui.js"></script>
	<script>


layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
  var laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
 
  
  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });
  
  //执行一个 table 实例
  table.render({
     elem: '#goods'
    ,height: 474
    ,url: '<%=basePath%>loginandregist/findAlls' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {type:'checkbox', fixed: 'left'}
      ,{field: 'user_id', title: '会员ID', width:150}
      ,{field: 'user_name', title: '会员名称', width:140}
      ,{field: 'user_pwd', title: '会员密码', width:140}
      ,{field: 'user_phone', title: '会员电话', width:180}
      ,{field: 'user_card', title: '会员身份证', width: 180}
      ,{field: 'isva', title: '是否有效', width: 100}
      ,{field: 'optime', title: '操作时间', width: 170}
      ,{fixed: 'right',title: '操作', width: 145, align:'center', toolbar: '#barDemo'}
    ]]
  	,id: 'testReload'
  });
  
//监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    if(layEvent === 'del'){
      var id=data.user_id;
    
      layer.confirm('确认删除？', function(index){
        /* obj.del(); */ //删除对应行（tr）的DOM结构
        layer.close(index);
        //使用jquery的ajax方式向后台提交数据
		var url = "<%=basePath%>loginandregist/userDelete";
		var data={id:id};
			$.post(url,data,function(data){
				layer.msg('删除成功', {
					  icon: 1,
					  time: 1000 //1秒关闭（如果不配置，默认是3秒）
				}, function(){
					// parent.location.reload();
					obj.del();
				});
				
			},"JSON");
      	});
    } else if(layEvent === 'edit'){
    	var id=data.user_id;

    	var name=data.user_name;
        //使用jquery的ajax方式向后台提交数据
		var url = "<%=basePath%>loginandregist/findById";
		var data={id:id};
		$.post(url,data,function(data){
		alert(data);
		 /* eval("var man="+data); */
		
		 layer.open({
			  type: 2,
			  area : ['60%' , '90%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: ['pages/yyf/userUpdate.jsp','on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		 	  success:function(layero,index){
		 		  var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
		 		  var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
		 		  console.log(body.html()) //得到iframe页的body内容
		 		 body.find("#userId").val(data.user_id);
		 		  body.find("#userName").val(data.user_name);
		 		  body.find("#userPwd").val(data.user_pwd);
		 		  body.find("#userPhone").val(data.user_phone);
		 		  body.find("#userCard").val(data.user_card);
		 		  body.find("#isva").val(data.isva);
		 		  body.find("#oper").val(data.oper);
		 	  }
			}); 
			   
		});
    }
  });
  
  //条件查询
  var $ = layui.$;
		  
  $('.demoTable .layui-btn').on('click', function(){
	 var demoReload = $('#demoReload');
	 //执行重载
     table.reload('testReload', {
				 url: '<%=basePath%>loginandregist/findUsersByName',
				 page: 1
			 ,where: {
          user_name: demoReload.val()
       }
     });
  });
  //增加
  $('#manAdd').on('click', function(){
	 layer.open({
		  type: 2,
		  area : ['60%' , '90%'],//弹出框大小
		  shift:1,//弹出框动画效果
		  content: ['pages/yyf/userAdd.jsp','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		}); 
   }); 
  
});
  
  
</script>
</body>
</html>
